﻿

let data = [{
    name: '桌子数量升序',
    isAsc: true,

},
{
    name: '桌子数量倒序',
    isAsc: false,

}]



var loadTalbe;


function BindTable(obj) {
    layui.use('table', function () {
        var table = layui.table;

        table.render({
            elem: '#table'
            , data:obj
           /* , cellMinWidth: 80*/ //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[
               
                { field: 'name', title: '桌子类型' },
                { field: 'tableCount', title: '桌子数量' },
                { title: '操作', toolbar: "#barDemo" }
            ]]
        });
        Peng.closeload(loadTalbe);
        

        table.on('tool(table)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            switch (layEvent) {

                case "detail":
                    sessionStorage.setItem("id", data.id)
                    sessionStorage.setItem("name", data.name)
                    location.href = "/Table/TableDetialsHtml"
                    break;
                case "del":
                    console.log(data.id)
                    break;
                case "edit":
                    sessionStorage.setItem("id", data.id)
                    sessionStorage.setItem("name", data.name)
                    location.href = "/Table/UpdateTableHtml"
                    break;
            }  
        })
       
    });
    
}




function GetTableType(key,isAsc) {


    loadTalbe = Peng.load({ box: 'Cols', style: 'circle', color: 'ZhutiSe', content: '加载桌子类型数据中.....' });

    $.get("/Table/GetTableType", { key: key, isAsc: isAsc}).then(res => {
        BindTable(res.data);
       

      

    });
}



var query = function ()
{

    GetTableType($("#Tnumber").val());

}


Peng_Select.CreateElement("StatusSelect", data, 'name', (res) => {
    GetTableType("",res.isAsc);
});

